package com.atguigu.cmsService.controller;


import com.atguigu.cmsService.entity.CrmBanner;
import com.atguigu.cmsService.service.CrmBannerService;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器(前台使用)
 * </p>
 *
 * @author Mr.Alan
 * @since 2020-08-22
 */
@RestController
@RequestMapping("/cmsService/user/banner")
@CrossOrigin
public class CrmBannerUserController {

    @Resource
    private CrmBannerService crmBannerService;

    @PostMapping("/list")
    @ApiOperation("首页轮播图")
    public R listBanner() {
        List<CrmBanner> list = crmBannerService.lambdaQuery()
                .select(CrmBanner::getId, CrmBanner::getTitle, CrmBanner::getImageUrl, CrmBanner::getLinkUrl, CrmBanner::getSort)
                .orderByAsc(CrmBanner::getSort).list();
        if (CollectionUtils.isNotEmpty(list)) {
            return R.ok().data("list", list);
        }
        return R.ok().data("list", Collections.emptyList());

    }


}

